package com.guit.hrms.mapper;

import com.guit.hrms.dto.approval.ApprovalPlanDTO;
import com.guit.hrms.po.Transaction;
import com.guit.hrms.po.approval.Approval;
import com.guit.hrms.po.approval.Depts;
import com.guit.hrms.po.approval.Position;
import com.guit.hrms.po.interview.Offer;
import com.guit.hrms.vo.ApprovalOfferVO;
import com.guit.hrms.vo.TransactionVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ApprovalMapper {
    /**
     * 查询请假/审批记录
     * @param deptId 部门id
     * @param type 请假类型
     * @param approvalStatus 审批状态
     * @param revokeStatus 销假状态
     * @return 请假/审批记录
     */
    List<TransactionVO> queryLeaveRecords(Integer deptId, Integer type, Integer approvalStatus, Integer revokeStatus, Integer extensionStatus);

    /**
     * 审批请假/销假
     * @param transaction 审批信息
     * @return 审批结果
     */
    Integer approvingLeave(Transaction transaction);

    /**
     *
     * @param planType
     * @return
     */
//    @Select("select plan_id,plan_name,plan_code,plan_type ,recruiter_id," +
//            "recruiter_name,recruiter_phone,recruitment_conditions,benefits_description," +
//            "start_date,end_date,publish_date,interview_process,approve_status,approver_id," +
//            "notes,attachments,created_by,updated_by,created_at,updated_at,content" +
//            " from recruitment_plan rp where plan_type = #{planType}")
    List<Approval> getRecruitmentPlan(Integer planType);

    /**
     * 根据计划id获取全部number
     * @param planId
     * @return
     */
    @Select("select distinct dept_id as numbering from plan_dept_job where plan_id = #{planId}")
    List<Depts> getAllDeptId(Long planId);

    /**
     * 根据计划id获取全部number
     * @param planId
     * @return
     */
    @Select("select distinct academy_id as numbering from plan_academy_job where plan_id = #{planId}")
    List<Depts> getAllAcademyId(Long planId);

    /**
     * 根据部门编号和计划id查询部门中间表
     * @param planId
     * @param numbering
     * @return
     */
    @Select("select *from plan_dept_job where plan_id = #{planId} and dept_id = #{numbering}")
    List<Position> getPositioToDept(Long planId, String numbering);

    /**
     *
     * @param planId
     * @param numbering
     * @return
     */
    @Select("select *from plan_academy_job where plan_id = #{planId} and academy_id = #{numbering}")
    List<Position> getPositionToAcademy(Long planId, String numbering);

    /**
     * 审批招聘计划（修改招聘计划的审批状态）
     * @param approvalPlanDTO 审批信息
     * @return 结果
     */
    @Update("update recruitment_plan set approve_status = #{approvalPlanDTO.approveStatus},approver_id = #{employeeId} where plan_id = #{approvalPlanDTO.planId}")
    Integer updateRecruitmentPlan(ApprovalPlanDTO approvalPlanDTO, String employeeId);

    /**
     * 获取发offer申请
     *
     * @param status 审批状态
     * @return 发offer申请列表
     */
    List<ApprovalOfferVO> getApplyOfferMsg(Integer status);

    @Select("select * from offer where id = #{id}")
    Offer getOfferMsgById(Integer id);

    /**
     * 审批发offer申请
     * @param offer 审批信息
     * @return 结果
     */
    Integer updateApplyOfferMsg(Offer offer);
}
